package com.janal.controller.Modify;

import com.janal.model.user.User;
import com.janal.service.modify.ModifyService;
import com.janal.service.modify.ModifyServiceImpl;
import com.mysql.cj.xdevapi.JsonString;
import net.sf.json.JSON;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class getMessageServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、从service中获取用户信息
        HttpSession session = req.getSession();
        String usercode = (String) session.getAttribute("usercode");
        ModifyService ms = new ModifyServiceImpl();
        User user = ms.getUserMessage(usercode);
        //2、转化成json格式的字符串
        JSONObject userJson = JSONObject.fromObject(user);
        //3、响应给客户端
        resp.getWriter().print(userJson);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
